<include file='public/_meta'>

<div class="page-container">
	<div class="Huialert Huialert-success"><i class="Hui-iconfont">&#xe6a6;</i>
		<p class="c-primary">
		 	操作提示
		</p>
		<ul>
		  <li>暂时只支持赛卡(博鹭途)</li>

		  <li>二代车机专用升级包，只能在二代车机中使用。如果在一代车机中使用会导致车机无法正常使用且必须人工去通过CAN接口重新升级</li>

		  
		</ul>
	</div>
	<form action="{:url('version')}" method="post" enctype="multipart/form-data" class="form form-horizontal mb-30" id="form-type-add">
		<input type="hidden" name="cars" value="{$cars}">
		<div class="row cl mb-30">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				选择版本:</label>
			<div class="formControls col-xs-6 col-sm-6">
				<span class="select-box" style="width:150px;">
                    <select class="select" name="version">
                        <option value="" style="color: #429842;">请选择</option>
                        <foreach $version as $value>
                        	<option value="{$value}">{$value}</option>
                    	</foreach>                       
                    </select>  
                </span> <span class="c-primary ml-20">
		 				已经选择({:substr_count($cars,'@')+1})辆车
		 				
						</span>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;确认提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
	<span class="c-red">*</span><span>环境切换</span>
	<div class="cl pd-5 bg-1 bk-gray mt-20 text-c">
        <span class=""> <a class="btn btn-primary radius" onclick="current('{$cars}')" href="javascript:;"><i class="Hui-iconfont"></i> 传统切IOT(当前环境)</a></span>  
        <span class="ml-50"> <a class="btn btn-success radius" onclick="car_env('{$cars}','dev')" href="javascript:;"><i class="Hui-iconfont"></i> IOT开发环境</a></span>
        <span class="ml-50"> <a class="btn btn-warning radius" onclick="car_env('{$cars}','test')" href="javascript:;"><i class="Hui-iconfont"></i> IOT测试环境</a></span> 
        <span class="ml-50"> <a class="btn btn-success radius" onclick="car_env('{$cars}','production')" href="javascript:;"><i class="Hui-iconfont"></i> IOT正式环境</a></span>  
    </div>
</div>

<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){

	$("#form-type-add").validate({
		rules:{
			version:{
				required:true,
				maxlength:60
			},
			
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				dataType: 'json',
				success: function(data) { 
				 	var index = parent.layer.getFrameIndex(window.name);
					//parent.$('.btn-refresh').click();
	                if(data['result']==0){
	                
	                	layer.msg(data['msg'], {icon:6,time:1000},function(){

							parent.location.href = '{:url('index/terminal/cars')}';              		
							// parent.layer.close(index);
	                	});
	                }else{
	                	layer.msg("指令发送失败");
	                }
	                
            	},
            	error:function(data){
					layer.msg('网络错误');
            	},


			});

		}
	});
});

function current(cars) {
    layer.confirm('确认要切换吗？',function(index){
        $.ajax({
            type: 'GET',
            url: "{:url('index/Terminal/current')}",
            data:{
            	'cars':cars
            },
            dataType: 'json',
            success: function(data){
                var index = parent.layer.getFrameIndex(window.name);
					//parent.$('.btn-refresh').click();
	                if(data['result']==0){
	                
	                	layer.msg(data['msg'], {icon:6,time:1000},function(){

							parent.location.href = '{:url('index/terminal/cars')}';              		
							// parent.layer.close(index);
	                	});
	                }else{
	                	layer.msg(data['msg']);
	                }
                
            },
            error:function(data) {
                console.log(data.msg);
            },
        });     
    });
    
}

function car_env(cars,car_env){
	layer.confirm('确认要切换吗？',function(index){
        $.ajax({
            type: 'GET',
            url: "{:url('index/Terminal/development')}",
            data:{
            	'cars':cars,
            	'car_env':car_env
            },
            dataType: 'json',
            success: function(data){
                var index = parent.layer.getFrameIndex(window.name);
					//parent.$('.btn-refresh').click();
	                if(data['result']==0){
	                
	                	layer.msg(data['msg'], {icon:6,time:1000},function(){

							parent.location.href = '{:url('index/terminal/cars')}';              		
							// parent.layer.close(index);
	                	});
	                }else{
	                	layer.msg(data['msg']);
	                }
                
            },
            error:function(data) {
                console.log(data.msg);
            },
        });     
    });
}
</script> 
<!--/请在上方写此页面业务相关的脚本-->